
var flagTable;
/**
 * 页面初始化
 */
$(function () {
	//设置年份的选择 
	var myYear= new Date(); 
	var startYear=myYear.getFullYear()-5;//起始年份 
	var endYear=myYear.getFullYear()+5;//结束年份 
	var obj=document.getElementById('myYear') 
	for (var i=startYear;i<=endYear;i++) 
	{ 
		obj.options.add(new Option(i,i)); 
	};

	$('.form-group .datetimepicker-default').datetimepicker();

//	初始化表格控件
	flagTable = $('#report_table').DataTable({
		"scrollX" : "100%",
		"scrollY" : "410px",
		"processing": true,
		"serverSide": true,
		"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
		"dom": '<"bottom"rtflp>',
		"searching": false,
		"pagingType": "full_numbers",
		"deferRender": true,
		"ajax": {
			"url": "/monthlyTurnoverReport/getMonthlyTurnoverReport.action",
			"data": function ( d ) {
				//高级搜索
				var shop_id = encodeURI($('#shop_id').val());
				var myYear = encodeURI($('#myYear').val());
				var myMonth = encodeURI($('#myMonth').val());
				var advData = {
						"shop_id": shop_id,
						"pay_year": myYear,
						"pay_month": myMonth
				};
				d.formJson = JSON.stringify(advData);
			}
		},
		"tableTools": {
			"sRowSelect": "bootstrap"
		},
		"columns": [{
            "data": "shopName"
        }, {
            "data": "orderCode"
        }, {
            "data": "shopType"
        },     
        {"render": function (data, type, row, meta) {
	            var result = "";
	            if (row.orderStatus == "a") {
	                 result = "待客审";
	            }else if (row.orderStatus == "i") {
	                 result = "审核完毕";
	            }else if (row.orderStatus == "k") {
		             result = "发货中";
		        }else if (row.orderStatus == "r") {
			         result = "发货";
				}else if (row.orderStatus == "z") {
			         result = "订单完成";
			    }
                return result;
            }
        },
        {
            "data": "tradeStatus"
        }, {
            "data": "payMode"
        }, {
            "data": "lgstCode"
        }, {
            "data": "lgstName"
        }, {
            "data": "lgstNo"
        }, {
            "data": "lgstFee"
        }, {
            "data": "invoiceType"
        },{
            "data": "paidFee"
        }, {
            "data": "discountFee"
        }, {
            "data": "pointFee"
        }, {
            "data": "paidDate"
        }
		],
	}).on('draw.dt',  function() {
		//解决因滚动条导致的列对不齐问题
		$(".dataTables_scrollBody").css("overflow-y","overlay");
		$("#report_table").find("th.sorting_asc").removeClass("sorting_asc");
	});

//	网店 初期化
	$.ajax({
		type : "GET",
		url : "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
		contentType : "application/json;charset=utf-8",
		dataType : "json",
		async : false,// 同步
		success : function(data) {
			if (data.result == "success") {
				$("#shop_id option").remove();
				$("#shop_id").append("<option value=''>请选择</option>");
				$.each(data.data, function(n, value) {
					$('#shop_id').append(
							"<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
				});
			} else {
				window.top.window.showModalAlert(data.msg);
			}
		},
		error : function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest.status == 500) {
				var result = eval("(" + XMLHttpRequest.responseText + ")");
				alert(result.errorObject.errorText);
			}
		}
	});

	// 搜索按钮点击
	$("#SearchSubmit").click(function () {
		flagTable.draw();
	});

	// 快速查询
	$("#btnQuickSearch").click(function() {
		quickSearch = encodeURI($('#quickSearch').val());
		flagTable.draw();
	});

	//点击重置按钮
	$("#resetBtn").click(function () {
		$('#shop_id').val("");
		$('#myYear').val("");
		$('#myMonth').val("");
	});
});
